<?php

/**
 * [get_follow_info 根据用户id获取用户特定信息]
 * @param  [type] $uid   [用户id]
 * @param  [type] $field [获取字段，如果不存在则获取所有信息]
 * @return [type]        [description]
 */
function get_follow_info($uid,$field=null){
    $m=M('follow');
    $where['id']=$uid;
    $where['status']=1;
    $info = null;
    if($field){
        $info=$m->where($where)->getField($field);
    }else{
        $info=$m->where($where)->find();
    }
    return $info;
}


/**
 * 获取涨跌活动的唯一标识 time值
 */
function get_now_time(){
    $day_time=mktime(13,00,00,date('m'),date('d'),date('Y'));
    if(time()>=$day_time){
        $time=get_time(strtotime(date('Ymd')),1);
    }else{
        $time=get_time(strtotime("-1 day"),1);
    }
    $result=M('rose_activity')->where("status=1")->order('periods_start_time desc')->find();
    if($time<date('Ymd',$result['periods_start_time'])){
        $time=date('Ymd',$result['periods_start_time']);
    }else if($time>date('Ymd',$result['periods_end_time'])){
        $time=date('Ymd',$result['periods_end_time']);
    }
    return $time;
}
/**
 * 获取排行榜中的总人数(当前参与的总人数加上假的人数)
 */
function ranking_count_persons($data){
     //加上虚拟人数
    $fictitious_data=F('fictitious_data');//虚拟金豆和人数的数据
    return count($data)+$fictitious_data['rise_num']+$fictitious_data['fall_num'];
}

/**
 * [modify_account 更改账户资金]
 * @param  [type] $openid [用户Openid]
 * @param  [type] $money  [操作金额]
 * @param  [type] $type   [操作类型]
 * @param  [type] $note   [操作说明]
 * @return [type]         []
 */
function modify_account($openid,$money,$type,$note){
    $where = array();
    $where['openid'] = $openid;
    $user = M('Follow')->field('id,money,route')->where($where)->find();
    //金额日志
    $total_money = $user['money']+$money;
    $res = M('Follow')->where($where)->setField(array('money'=>$total_money));
    if($res){
        //金额日志
        $data['user_id']=$user['id'];
        $data['money'] = $money;
        $data['type'] = $type;
        $data['note'] = $note;
        $balance = M('Follow')->where($where)->getField('money');
        $data['balance'] = $balance;
        $data['create_time'] = time();
        $res2 = M('FuturesFundRecord')->data($data)->add();
    }
}

/**
 * [get_futures_data 获取期货实时数据]
 * @param  string $type [期货类别commodity：商品期货，stock:股指期货]
 * @param  [type] $time [null:实时数据，MiniKLine5m：5分分时线，15,30，60，day]
 * @return [type]       [description]
 */
function get_futures_data($code='',$futuresType='commodity'){
    if(empty($code)) return false;
    if($futuresType=="stock"){
        $code = "CFF_RE_".$code;
    }
    $url = "http://hq.sinajs.cn/list={$code}";
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);

    //exit;
    $output = mb_convert_encoding($output, 'utf-8', 'gbk');
    $data = futures_data($output);
    //dump($data);
    //echo'<hr>';
    if(count($data)>1){
        return $data;
    }else{
        return false;
    }
    
}

function futures_data($data){
    //=分割
    $data = trim($data,'"');
    $arr = explode('=',$data);
    //,分割
    $arr[1]=trim($arr[1],'"');
    $futuresData = explode(',',$arr[1]);
    return $futuresData;
}

/**
 * 获取某个时间几天之后的时间(除去节假日)
 * @param int $date_time  时间
 * @param int $days  天数
 * @return int
 */
function get_time($date_time,$days){
	
    //获取$date_time经过$days天之后的时间
    $result=date('Ymd',$date_time+$days*24*3600);
    //检查其中是否有节假日
    $str='';
    $str.=date('Ymd',$date_time+$days*24*3600).',';
    $res=is_rest(rtrim($str,','));
    $index=0;
    if($res){
        foreach($res as $val){
            if($val){
                $index++;
            }
        }
    }
    //如果有节假日，则向后推延
    if($index){
        $result=get_time(strtotime($result),$index);
    }
    return $result;
}
/**
 * 获取某个时间几天之前的时间(除去节假日)
 * @param int $date_time  时间
 * @param int $days  天数
 * @return int
 */
       
 function get_time_pre($date_time,$days){
    //获取$date_time经过$days天之后的时间
    $result=date('Ymd',$date_time-$days*24*3600);
    //检查其中是否有节假日
    $str='';
    for($i=1;$i<=$days;$i++){
        $str.=date('Ymd',$date_time-$i*24*3600).',';
    }
    $res=is_rest(rtrim($str,','));
    $index=0;
    if($res){
        foreach($res as $val){
            if($val){
                $index++;
            }
        }
    }
    //如果有节假日，则向后推延
    if($index){
        $result=get_time_pre(strtotime($result),$index);
    }
    return $result;
}
/**
 * 检查某个日期是否是工作日，休息日，节假日
 * @param  string $time 20151030
 * @return string   空为时期不正确，0为工作日，1为休息日，2为节假日
 */
function is_rest($time){
    $url="http://www.easybots.cn/api/holiday.php?d=".$time;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $output = mb_convert_encoding($output, 'utf-8', 'gbk');
    if($output){
        $output=json_decode($output,true);
    }
    return $output;
}
    
    function send_wx_notify($openid,$title,$content,$w_url,$picurl){
        $access_token = getAccessToken();
        // $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
        // $post_msg = '{
        //     "touser":"'.$openid.'",
        //     "msgtype":"news",
        //     "news":{
        //         "articles": [
        //         {
        //             "title":"'.$title.'",
        //             "description":"'.$content.'",
        //             "url":"'.$w_url.'",
        //             "picurl":"'.$picurl.'"
        //         }
        //         ]
        //     }
        // }';
        $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token;
     
        $template=array(
            "template_id"=>"tIJl6e6Lt_u1i3daY-ohfeMKUl_idyqXE7arZgj-PKI",
            'touser'=>$openid,
            'url'=>$w_url,
            'topcolor'=>'#FF0000',
            'data'=>array(
                'first'=>array('value'=>$title,'color'=>'#743A3A'),
                'keyword1'=>array('value'=>$content['transaction_id'],'color'=>'#743A3A'),
                'keyword2'=>array('value'=>$content['close_time'],'color'=>'#743A3A'),
                //'remark'=>array('value'=>$content['other'],'color'=>'#743A3A'),
            ),
        );
        $post_msg=urldecode(json_encode($template));
        $ret_json = curl_grab_page($url, $post_msg);
        $ret = json_decode($ret_json);
        if($ret->errmsg != 'ok') {
            $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
            $ret_json = curl_grab_page($url, $post_msg);
            $ret = json_decode($ret_json);
        }

    }

    function getAccessToken(){
        $file = './Data/token.json';
        if(!file_exists($file) || (file_exists($file) && (time()-filemtime($file))>20)){
            $code=$_GET['code'];
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx8faec8023738e5f9&secret=5351249fac9acccc095728b9fabc7d66"; 
            $tmpInfo=httpGet($url);
            $info=json_decode($tmpInfo,true);
            $result['access_token']=$info['access_token'];
            file_put_contents($file,json_encode($result));
        }
        $data=file_get_contents($file);
        $data= json_decode($data,true);
        return $data['access_token'];
    }
    function httpGet($url, $data = null){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        if(curl_errno($ch)){
            return curl_error($ch);
        }
        curl_close($ch);
        return $tmpInfo;
    }
    function curl_grab_page($url,$data,$proxy='',$proxystatus='',$ref_url=''){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if ($proxystatus == 'true'){
            curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
            curl_setopt($ch, CURLOPT_PROXY, $proxy);
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        if(!empty($ref_url)){
            curl_setopt($ch, CURLOPT_HEADER, TRUE);
            curl_setopt($ch, CURLOPT_REFERER, $ref_url);
        }
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        ob_start();
        return curl_exec ($ch);
        ob_end_clean();
        curl_close ($ch);
        unset($ch);
    }

function modify_voucher($user_id,$voucher_id,$count,$type,$note){
    $voucher_where['user_id'] = $user_id;
    $voucher_where['voucher_id'] = $voucher_id;
    $voucher_where['count'] = array('gt',0);   //未使用
    //$voucher_where['overdue_time'] = array('gt',time());
    if($type==2){ //使用
        $res = M('FuturesVoucherRecords')->where($voucher_where)->setDec('count',$count); 
    }elseif($type==1){ //新增
        $res = M('FuturesVoucherRecords')->where($voucher_where)->setInc('count',$count); 
    }
    
    //金额日志
    $data['user_id']=$user_id;
    $data['voucher_id'] = $voucher_id;
    unset($voucher_where['count']);
    $money = M('FuturesVoucherRecords')->where($voucher_where)->getField('money');
    $data['money'] = $money;
    $data['count'] = $count;
    $data['type'] = $type;
    $data['note'] = $note;
    $data['create_time'] = time();
    $res2 = M('FuturesVoucherLog')->add($data);
    
}

function get_url() {
    $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
    $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
    $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
    $url=$sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
    $url=rtrim($url,'.html');
    return $url;
}
/**
 * 检测验证码
 * @param  integer $id 验证码ID
 * @return boolean     检测结果
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
function check_verify($code, $id = 2){
	$verify = new \Think\Verify();
	return $verify->check($code, $id);
}

// function get_stock_data($code='HSI1603'){
//     if(empty($code)) return false;
   
//     $url = "http://quote.jiaoyidaren.com/quote?code={$code}&_=".time();
//     //dump($url);
//     $ch = curl_init();
//     curl_setopt($ch, CURLOPT_URL, $url);
//     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//     curl_setopt($ch, CURLOPT_HEADER, 0);
//     $output = curl_exec($ch);
//     curl_close($ch);

//     //exit;
//     $output = mb_convert_encoding($output, 'utf-8', 'gbk');
//     //$data = futures_data($output);
//     //dump($output);
//     //echo'<hr>';
//     //截取单引号之间的内容
//     preg_match_all("/\'(.*?)\'/",$output,$data);
//     //dump($data[1][0]);
//     $datas = explode(',',$data[1][0]);
//     foreach($datas as $k=>$v){
//         $datas[$k] = number_format($v,2,'.','');
//     }
//     //涨幅
//     $option['sell_price'] = $datas[1]?$datas[1]:0.00;   //卖出价
//     $option['buy_price'] = $datas[3]?$datas[3]:0.00;    //买入价
//     $option['open_price'] = $datas[16]?$datas[16]:0.00; //开盘价
//     $option['last_price'] = $datas[9]?$datas[9]:0.00;   //最新价
//     $up = floatval($option['last_price'])-floatval($option['open_price']);
//     $up = number_format($up,2,'.','');    //差值
//     $ups = ($up/$option['open_price'])*100;
//     $ups = round($ups,2);             //涨幅
//     $option['up'] = $up;
//     $option['ups'] = $ups;
//     //dump($datas);
//     return $option;
// }

//欧指读取行情数据，数据库读取
function get_stock_data($code='HSI1603'){
	
	
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_stock_data";
	$url = U("GetData/get_stock_data");
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    /*
	$Mongo= new  \Common\Model\QuotationModel('optiondatas');
	$where['type'] = 1;
	$datas = $Mongo->where($where)->order('id desc')->limit(1)->select();
	foreach($datas as $k=>$v){
		$data=$v;
	}
	unset($data['_id']);
	*/
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,2,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,2);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//欧指读取行情数据，数据库读取
function get_stock_data2($code='HSI1603'){
	/*
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_stock_data";
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    */
	
	$Mongo= new  \Common\Model\QuotationModel('optiondatas');
	$where['type'] = 1;
	$datas = $Mongo->where($where)->order('id desc')->limit(1)->select();
	foreach($datas as $k=>$v){
		$data=$v;
	}
	unset($data['_id']);
	
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,2,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,2);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//欧指读取行情数据，数据库读取
function get_euro_data($code='WICMECM0'){
	
	
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_euro_data";
	$url = U("GetData/get_euro_data");
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    /*
	$Mongo= new  \Common\Model\QuotationModel('optiondatas');
	$where['type'] = 2;
	$datas = $Mongo->where($where)->order('id desc')->limit(1)->select();
	foreach($datas as $k=>$v){
		$data=$v;
	}
	unset($data['_id']);
	*/
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,5,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,4);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//伦敦金读取行情数据，数据库读取
function get_gold_data($code='CMGCA0'){
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_gold_data";
	$url = U("GetData/get_gold_data");
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,1,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,4);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//美元读取行情数据，数据库读取
function get_dollar_data($code='CMGCA0'){
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_dollar_data";
	$url = U("GetData/get_dollar_data");
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,3,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,4);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//德指读取行情数据，数据库读取
function get_dax_data($code='CMGCA0'){
    $url = "http://cd.fivip.com/futures.php?s=/GetData/get_dollar_data";
	$url = U("GetData/get_dax_data");
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    
    $option['sell_price'] = $data['sell_price']?$data['sell_price']:0.00;   //卖出价
    $option['buy_price'] = $data['buy_price']?$data['buy_price']:0.00;    //买入价
    $option['open_price'] = $data['open_price']?$data['open_price']:0.00; //开盘价
    $option['last_price'] = $data['last_price']?$data['last_price']:0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,3,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,4);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

//比特币读取行情数据，数据库读取
function get_bite_data(){
    $url = "http://api.huobi.com/staticmarket/ticker_btc_json.js";
    //dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($output,true);
    //var_dump(date('Ymd H:i:s',$data['time']));exit;
    $option['time'] = $data['time'];
    $option['sell_price'] = $data['ticker']['sell']?sprintf("%.2f",$data['ticker']['sell']+0.3):0.00;   //卖出价
    $option['buy_price'] = $data['ticker']['buy']?sprintf("%.2f",$data['ticker']['buy']-0.3):0.00;    //买入价
    $option['open_price'] = $data['ticker']['open']?sprintf("%.2f",$data['ticker']['open']):0.00; //开盘价
    $option['last_price'] = $data['ticker']['last']?sprintf("%.2f",$data['ticker']['last']):0.00;   //最新价
    $up = $option['last_price']-$option['open_price'];
    $up = number_format($up,3,'.','');    //差值
    $ups = ($up/$option['open_price'])*100;
    $ups = round($ups,4);             //涨幅
    $option['up'] = $up;
    $option['ups'] = $ups;
    //dump($option);
    return $option;
}

/**
 * [get_stock_data_to_insert 获取行情数据]
 * @param  string $code [期权代码]
 * @return [type]       [行情字符串]
 */
function get_data_to_insert($code='HIHSI04'){
    if(empty($code)) return false;
    //$url = "http://quote.jiaoyidaren.com/quote?code={$code}&_=".time();
    $url = 'http://db2015.wstock.cn/wsDB_API/stock.php?market='.$code.'&num=200&u=fivip100&p=yixi888';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate, sdch");  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    if(empty($output)) return false;
    return $output;
}
?>
